#include "database/cty_dat_parser.h"
#include <iostream>
#include <string>
#include <vector>

int main() {
    CTYDatParser parser;
    
    // 加载CTY.DAT文件
    std::string filepath = "../config/wl_cty.dat";
    if (!parser.loadFromFile(filepath)) {
        std::cerr << "Error loading file: " << parser.getLastError() << std::endl;
        return 1;
    }
    
    std::cout << "CTY.DAT file loaded successfully!" << std::endl;
    
    // 测试一些基本呼号查询
    std::vector<std::string> test_callsigns = {
        "BY1AA",      // 中国
        "W1AW",       // 美国
        "VE3ABC",     // 加拿大
        "DL5XYZ",     // 德国
        "JA1DEF",     // 日本
        "VK2GHI",     // 澳大利亚
        "RA4NCC"      // 俄罗斯
    };
    
    std::cout << "=== Basic Callsign Tests ===" << std::endl;
    for (const auto& callsign : test_callsigns) {
        const auto* info = parser.lookupCountry(callsign);
        if (info) {
            std::cout << "Callsign: " << callsign << std::endl;
            std::cout << "  Country: " << info->country_name << std::endl;
            std::cout << "  CQ Zone: " << info->cq_zone << std::endl;
            std::cout << "  ITU Zone: " << info->itu_zone << std::endl;
            std::cout << "  Continent: " << info->continent << std::endl;
            std::cout << "  Latitude: " << info->latitude << std::endl;
            std::cout << "  Longitude: " << info->longitude << std::endl;
            std::cout << "  UTC Offset: " << info->utc_offset << std::endl;
            std::cout << "  Primary Prefix: " << info->primary_prefix << std::endl;
            std::cout << "  WAEDC: " << (info->is_waedc ? "Yes" : "No") << std::endl;
            std::cout << std::endl;
        } else {
            std::cout << "No country found for callsign: " << callsign << std::endl << std::endl;
        }
    }
    
    // 测试带斜杠的呼号
    std::vector<std::string> slash_callsigns = {
        "W1AW/P",     // 美国/便携
        "VE3ABC/MM",  // 加拿大/移动
        "DL5XYZ/QRP"  // 德国/QRP操作
    };
    
    std::cout << "=== Portable/Mobile Callsign Tests ===" << std::endl;
    for (const auto& callsign : slash_callsigns) {
        const auto* info = parser.lookupCountry(callsign);
        if (info) {
            std::cout << "Callsign: " << callsign << std::endl;
            std::cout << "  Country: " << info->country_name << std::endl;
            std::cout << "  CQ Zone: " << info->cq_zone << std::endl;
            std::cout << "  ITU Zone: " << info->itu_zone << std::endl;
            std::cout << "  Continent: " << info->continent << std::endl;
            std::cout << "  Latitude: " << info->latitude << std::endl;
            std::cout << "  Longitude: " << info->longitude << std::endl;
            std::cout << "  UTC Offset: " << info->utc_offset << std::endl;
            std::cout << "  Primary Prefix: " << info->primary_prefix << std::endl;
            std::cout << "  WAEDC: " << (info->is_waedc ? "Yes" : "No") << std::endl;
            std::cout << std::endl;
        } else {
            std::cout << "No country found for callsign: " << callsign << std::endl << std::endl;
        }
    }
    
    // 测试特殊的前缀
    std::vector<std::string> special_prefixes = {
        "3V",         // 突尼斯
        "5A",         // 利比亚
        "7J",         // 俄罗斯亚洲部分
        "9K"          // 科威特
    };
    
    std::cout << "=== Special Prefix Tests ===" << std::endl;
    for (const auto& callsign : special_prefixes) {
        const auto* info = parser.lookupCountry(callsign);
        if (info) {
            std::cout << "Callsign: " << callsign << std::endl;
            std::cout << "  Country: " << info->country_name << std::endl;
            std::cout << "  CQ Zone: " << info->cq_zone << std::endl;
            std::cout << "  ITU Zone: " << info->itu_zone << std::endl;
            std::cout << "  Continent: " << info->continent << std::endl;
            std::cout << std::endl;
        } else {
            std::cout << "No country found for callsign: " << callsign << std::endl << std::endl;
        }
    }
    
    // 显示加载的国家数量
    std::cout << "Total countries loaded: " << parser.getAllCountries().size() << std::endl;
    
    return 0;
}